package cn.edu.cdut.controller;

import cn.edu.cdut.dto.MyRes;
import cn.edu.cdut.model.PlanCourseInfo;
import cn.edu.cdut.service.PlanCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

/**
 * Author  kobe
 * Created on 2017-05-31-17:34
 */
@RestController
public class PlanCourseController {

        @Autowired
        private PlanCourseService planCourseService;

        //查
        @GetMapping("/getAllCourse")
        public MyRes getAllCourse() {
                return planCourseService.getAllCourse();
        }

        //增
        @PostMapping("/addCourses")
        public MyRes addCourses(@RequestBody PlanCourseInfo planCourseInfo, BindingResult bindingResult) {
                if (bindingResult.hasErrors()) {
                        return new MyRes(201, "提交失败！", null);
                }
                planCourseService.addCourses(planCourseInfo);
                return new MyRes(200, "提交成功！", null);
        }

        //改
        @PostMapping("/updateCourse")
        public MyRes updateCourse(@RequestBody PlanCourseInfo planCourseInfo, BindingResult bindingResult) {
                if (bindingResult.hasErrors()) {
                        return new MyRes(201, "提交失败！", null);
                }
                return planCourseService.updateCourse(planCourseInfo);
        }

        //删
        @GetMapping("/removeCourse")
        public MyRes removeCourse( @RequestParam("id") Long id ) {
                return planCourseService.removeSpeciality(id);
        }
}
